/**
 * 
 */
package javas.thread;

/**
 * @author lionbule
 * 
 */
public class TestThreadInterrupt {
	static volatile boolean stop = false;
	
	final static boolean isStop(){
		return stop;
	}
	
	public static void main(String[] args) {
		Thread testThread = new Thread(new Runnable() {
			private volatile long count = 0;

			@Override
			public void run() {
				while (!isStop()) {
					System.out.println("count=" + count++);
					try {
						Thread.currentThread().sleep(3000);
						if(Thread.currentThread().isInterrupted()){
							break;
						}
					} catch (InterruptedException e) {
					}
					
				}
			}
		});
		testThread.setName("testThread");
		testThread.start();
		
		try {
			Thread.sleep(6005L);
			stop = true;
			testThread.interrupt();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
	}
}
